package com.zw.yzk.kabu.base;


import android.os.Bundle;
import android.support.annotation.Nullable;
import butterknife.ButterKnife;
import com.jaeger.library.StatusBarUtil;
import com.zw.yzk.kabu.R;
import com.zw.yzk.kabu.internal.component.ApplicationComponent;
import com.zw.yzk.kabu.management.ActivityManager;
import skin.support.app.SkinCompatActivity;
import skin.support.content.res.SkinCompatResources;

/**
 * Created by zhanwei on 2016/12/23.
 * support skin by Sky 2017/4/14
 */

public abstract class BaseActivity extends SkinCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());

        //添加Activity到Activity栈
        ActivityManager.getInstance().addActivity(this);
        //注册butternife
        ButterKnife.bind(this);
        initComponent();
        initView();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //解注册butternife
        ButterKnife.unbind(this);
        //将Activity从Activity栈移除
        ActivityManager.getInstance().removeActivity(this);
    }

    public ApplicationComponent getApplicationComponent() {
        return ((BaseApplication) getApplication()).getApplicationComponent();
    }

    /**
     * 获取布局文件ID
     *
     * @return activity布局
     */
    public abstract int getLayoutId();

    /**
     * 初始化视图
     */
    public void initView() {
        //初始化导航栏
        iniToolbar(this);
    }

    /**
     * 创建导航栏
     *
     * @param activity 打开的activity
     */
    public abstract void iniToolbar(BaseActivity activity);

    /**
     * 初始化component
     */
    public abstract void initComponent();

    /**
     * 设置状态栏颜色
     */
    @Override
    protected void updateStatusBarColor() {
        if(!skinStatusBarColorEnable()) return;
        // PhoneUtils.setStatusBarColor 这里不行
        StatusBarUtil.setColor(this, SkinCompatResources.getInstance().getColor(R.color.toolbar_bg), 0);
    }
}
